﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Printing;
using System.Windows.Forms;
using Logs;

namespace Common {
    public class Print {
        private PrintDialog printDialog = new PrintDialog();
        private string filePath;

        public Print() {
        }

        public Print(string filePath) {
            this.filePath = filePath;
            this.printDialog.UseEXDialog = true;
        }

        /// <summary>
        /// 直接打印
        /// </summary>
        public bool PrintDirectly() {
            bool status = false;
            try {
                if(printDialog.ShowDialog() == DialogResult.OK) {

                    Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
                    doc.LoadFromFile(this.filePath);
                    PrintDocument printDoc = doc.PrintDocument;
                    printDoc.Print();
                    status = true;
                }
            } catch(Exception ex) {
                Log.Error(ex.Message);
                status = false;
            }
            return status;
        }
    }
}
